package sh_goods

// 基础结构
type District struct {
	Label string `json:"label"`
	Pid   int    `json:"pid"`
	Value int    `json:"value"`
}

// 返回的数据结构 select
type DistrictSelectTree struct {
	Value    int                   `json:"value"`
	Label    string                `json:"label"`
	Children []*DistrictSelectTree `json:"children"`
}

// 数据
var SecondhandDistrict = map[int]*District{
	100: &District{
		Label: "上海",
		Value: 100,
		Pid:   0,
	},
	100101: &District{
		Label: "奉贤区",
		Value: 100101,
		Pid:   100,
	},
	100102: &District{
		Label: "闵行区",
		Value: 100102,
		Pid:   100,
	},
	200: &District{
		Label: "浙江",
		Value: 200,
		Pid:   0,
	},
	200101: &District{
		Label: "杭州",
		Value: 200101,
		Pid:   200,
	},
	200101001: &District{
		Label: "大悦城",
		Value: 200101001,
		Pid:   200101,
	},
}

// 数据
var SecondhandDistrict1 = map[int]*District{
	100: &District{
		Label: "(大马尼拉)Metro Manila",
		Value: 100,
		Pid:   0,
	},
	100101: &District{
		Label: "(马尼拉)Manila",
		Value: 100101,
		Pid:   100,
	},
	100102: &District{
		Label: "(曼达卢永)Mandaluyong",
		Value: 100102,
		Pid:   100,
	},
	100103: &District{
		Label: "(马里基纳)Marikina",
		Value: 100103,
		Pid:   100,
	},
	100104: &District{
		Label: "(帕西市)Pasig",
		Value: 100104,
		Pid:   100,
	},
	100105: &District{
		Label: "(奎松市)Quezon City",
		Value: 100105,
		Pid:   100,
	},
	100106: &District{
		Label: "(圣胡安)San Juan",
		Value: 100106,
		Pid:   100,
	},
	100107: &District{
		Label: "(卡洛奥坎)Caloocan",
		Value: 100107,
		Pid:   100,
	},
	100108: &District{
		Label: "(马拉邦)Malabon",
		Value: 100108,
		Pid:   100,
	},
	100109: &District{
		Label: "(纳沃塔斯)Navotas",
		Value: 100109,
		Pid:   100,
	},
	100110: &District{
		Label: "(巴伦苏埃拉)Valenzuela",
		Value: 100110,
		Pid:   100,
	},
	100111: &District{
		Label: "(拉斯皮尼亚斯)Las Piñas",
		Value: 100111,
		Pid:   100,
	},
	100112: &District{
		Label: "(馬卡蒂市)Makati",
		Value: 100112,
		Pid:   100,
	},
	100113: &District{
		Label: "(蒙廷卢帕)Muntinlupa",
		Value: 100113,
		Pid:   100,
	},
	100114: &District{
		Label: "(帕拉尼亚克)Parañaque",
		Value: 100114,
		Pid:   100,
	},
	100115: &District{
		Label: "(帕賽市)Pasay",
		Value: 100115,
		Pid:   100,
	},
	100116: &District{
		Label: "(帕特罗斯)Pateros",
		Value: 100116,
		Pid:   100,
	},
	100117: &District{
		Label: "(塔吉格)Taguig",
		Value: 100117,
		Pid:   100,
	},
	100117001: &District{
		Label: "(环球城)BGC",
		Value: 10011701,
		Pid:   100117,
	},
	100117002: &District{
		Label: "(环球城)BGC",
		Value: 100117002,
		Pid:   100117,
	},
}

// @title DistrictSelectTree
// @description 构建tree
func BuildDistrictTree(pid int) []*DistrictSelectTree {
	data := make([]*DistrictSelectTree, 0)
	for itemId, item := range SecondhandDistrict {
		if item.Pid == pid {
			tmpObj := DistrictSelectTree{
				Value: itemId,
				Label: item.Label,
			}
			tmpObj.Children = BuildDistrictTree(item.Value)
			data = append(data, &tmpObj)
		}
	}

	return data
}

// 获取District
func GetDistrict(id int) *District {
	if _, ok := SecondhandDistrict[id]; ok {
		return SecondhandDistrict[id]
	}
	return nil
}

// 获取 GetDistrictName
func GetDistrictName(id int) string {
	if _, ok := SecondhandDistrict[id]; ok {
		return SecondhandDistrict[id].Label
	}
	return "未知地区"
}
